﻿function showAttachmentALink(url, container, title, className) {
    if ((url + "").length <= 0) {
        $('#' + container).html('还没有上传');
    }
    else {
        var alink = $("<a target='_blank' href='" + "../../attachments/" + url + "'>点击查看</a>");
        alink.html(title);
        alink.attr("class", className);
        alink.appendTo('#' + container);
    }
}

function AddressJoin(provincialID, cityID, areaID, addressName)
{
    var provinceName;
    var citys;
    for (var provinceIndex in provinces) {
        if (provinces[provinceIndex].number == provincialID)
        {
            provinceName = provinces[provinceIndex].name;
            citys = provinces[provinceIndex].citys;
            break;
        }
    }

    var cityname;
    var areas;
    if (citys)
    {
        for (var cityIndex in citys) {
            if (citys[cityIndex].number == cityID) {
                cityname = citys[cityIndex].name;
                areas = citys[cityIndex].areas;
                break;
            }
        }
    }

    var areaName;
    if (areas) {
        for (var areaIndex in areas) {
            if (areas[areaIndex].number == areaID) {
                areaName = areas[areaIndex].name;
                break;
            }
        }
    }

    return provinceName+" "+cityname+" "+areaName+" "+addressName;
}

$(document).ready(function () {


    var passBtn = $('#PassBtn');
    var state = $('#state');
    if (passBtn) {
        passBtn.click(function () {
            state.val($('#Pass').val())
            passBtn.submit();
        })


    }

    var unfinishedBtn = $('#unfinishedBtn');
    if (unfinishedBtn) {
        unfinishedBtn.click(function () {
            state.val($('#unfinished').val())
            unfinishedBtn.submit();
        });


    }


    var workAddressTd = $('#workAddress');
    var workAddressProvincialID = $('#WorkInfo_ProvincialID');
    var workAddressCountyID = $('#WorkInfo_CountyID');
    var workAddressCityID = $('#WorkInfo_CityID');
    var workAddressAreaName = $('#WorkInfo_AreaName');
    if (workAddressProvincialID && workAddressCountyID && workAddressCityID && workAddressAreaName)
    {
        workAddressTd.text(AddressJoin(workAddressProvincialID.val(), workAddressCountyID.val(), workAddressCityID.val(), workAddressAreaName.val()));
    }


    var accountAddressInfoTd = $('#accountInfoAddress');
    var accountAddressInfoProvincialID = $('#AccountInfo_ProvincialID');
    var accountAddressInfoCountyID = $('#AccountInfo_CountyID');
    var accountAddressInfoCityID = $('#AccountInfo_CityID');
    var accountAddressInfoAreaName = $('#AccountInfo_AreaName');
    if (accountAddressInfoProvincialID && accountAddressInfoCountyID && accountAddressInfoCityID && accountAddressInfoAreaName) {
        accountAddressInfoTd.text(AddressJoin(accountAddressInfoProvincialID.val(), accountAddressInfoCountyID.val(), accountAddressInfoCityID.val(), accountAddressInfoAreaName.val()));
    }

    $('#BackBtn').click(function () {

        window.location = $('#urlReferrer').val();
    });
});